package controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Map;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.bean.ServiceInfo;
import model.bo.TourUpdateBO;

/**
 * Servlet implementation class TourServiceServlet
 */
public class TourServiceServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public TourServiceServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	    doPost(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	    Map element = request.getParameterMap();
        TourUpdateBO bo = null;
        String action = request.getParameter("action");
        if (element.containsKey("btStatistic")) {
            bo = new TourUpdateBO();
            int type = Integer.parseInt(request.getParameter("object").trim());
            String dayStart = request.getParameter("tfDayStart");
            String dayEnd = request.getParameter("tfEndDay");
            int odd = Integer.parseInt(request.getParameter("order"));
            String order = odd==1?"ASC":"DESC";
            
            ArrayList<ServiceInfo> listService = bo.getServiceList(type, dayStart, dayEnd, order);
            for(int i = 0; i < listService.size(); i++) {
                System.out.println(listService.get(i).getSvName());
            }
            request.setAttribute("listService",listService);
            RequestDispatcher rd = request.getRequestDispatcher("tourmanager.jsp?#ServiceMng");
            rd.forward(request, response);
            
        }
	}

}
